< previous page page_436 next page >

Page 436
The PaintPicture Method
The PaintPicture method works exactly like it sounds; it paints a picture from one object onto another. By carefully setting the height and width arguments for the source and target objects, you can enlarge or reduce the size of the source picture. The following code paints part of a picture from a PictureBox control onto a form:
frmdest.PaintPicture picSource.Picture, 50, 50, 750, 750, 0, 0, 500, 500
The code in the preceding line takes a piece of a picture from the PictureBox control picSource, enlarges it, and places it on the form frmDest. As you can see, the PaintPicture method contains several arguments:
Source Picture. All or part of this source picture is drawn in a ''target region" on the destination object.
Target X and Y. These two numerical arguments specify the coordinates of the upper-left corner of the target region. In the preceding line of code, drawing occurs on frmDest 50 scale units (in this case twips) from the left edge and 50 scale units from the top edge.
Target Size. This argument specifies the horizontal and vertical size of the target region. If this size is different from the source picture or region, the picture is stretched or compressed to fit the target region.
Source X and Y. The third pair of numbers in the command specifies the upper-left corner of the source regionthat is, the part of the picture being copied.
Source Size. This argument specifies the height and width of the source region.
These first three arguments are the only ones that are required for the PaintPicture method. All other arguments are optional. If only the three required arguments are specified, the entire source picture is copied to the target at full size.
The following are some uses of the PaintPicture method in creating graphics:
To provide a zoom feature for looking more closely at specific regions of a picture. This capability would be useful for implementing print preview in your application.
To copy or clear a specified region of a picture.
To move the contents of a PictureBox control to the Printer objectfor example, to put a company logo on your report.
For an example that uses PaintPicture and some of the other methods discussed so far, see the application in Figure 19.7.
This application captures song title and artist information from a satellite TV music service. Here's how it works:
1. Code in a Timer control activates the "Snappy" video capture device to capture the current picture on the TV screen. The result of the video capture is stored in the Picture property of the Snappy custom control.
2. The PaintPicture method is used to copy the bottom section with the displayed song information from the Snappy control to the larger PictureBox control at the right of the form.

 
< previous page page_436 next page >